<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/view/common/easycommon.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>动态表单</title>
  <meta charset="utf-8">
  <style>
    .btndiv{
      padding-top:10px;
      text-align:center;
      display: inline-block;
      width:100%
    }
  </style>
</head>
<body>
  <form action="" method="post" id="taskTableForm" name="taskTableForm">
    <input type="hidden" id="taskId" name="taskId" value="${taskId}"/>
    <input type="hidden" id="taskUserId" name="taskUserId" value="${taskUserId}"/>
    <table style="width:100%;">
      <c:forEach items="${dataList}" var="tpl">
        <c:choose>
          <c:when test="${tpl.type==0  and tpl.itemType==0}"><!--普通文本类型-->
            <tr>
              <td style="width:15%;padding:5px;text-align: right">
                <label style="font-size:14px;">${tpl.name}:</label>
              </td>
              <td style="width:85%;padding:5px">
                <input class="easyui-textbox"  name="${tpl.columnCode}" id="${tpl.columnCode}" style="width:300px" value="${tpl.value}">
              </td>
            </tr>
          </c:when>

          <c:when test="${tpl.type==1  and tpl.itemType==0}"><!--日期类型-->
            <tr>
              <td style="width:15%;padding:5px;text-align: right">
                <label style="font-size:14px;">${tpl.name}:</label>
              </td>
              <td style="width:85%;padding:5px">
                <input class="mytextbox" id="${tpl.columnCode}" name="${tpl.columnCode}" style="width:300px" onfocus="WdatePicker({dateFmt:'yyyy-M-d'})" value="${tpl.value}"/>
              </td>
            </tr>
          </c:when>

          <c:when test="${tpl.type==2  and tpl.itemType==0}"><!--数字类型-->
            <tr>
              <td style="width:15%;padding:5px;text-align: right">
                <label style="font-size:14px;">${tpl.name}:</label>
              </td>
              <td style="width:85%;padding:5px">
                <input class="easyui-textbox"  name="${tpl.columnCode}" id="${tpl.columnCode}" style="width:300px" value="${tpl.value}">
              </td>
            </tr>
          </c:when>

          <c:when test="${tpl.type==3 and tpl.itemType==0}"><!--富文本类型-->
            <tr>
              <td style="width:15%;padding:5px;text-align: right">
                <label style="font-size:14px;">${tpl.name}:</label>
              </td>
              <td style="width:85%;padding:5px">
                <textarea class="mytextbox" name="${tpl.columnCode}" id="${tpl.columnCode}" style="width:90%;height:360px" >${tpl.value}</textarea>
                <script>
                  var editor_${tpl.columnCode};
                  KindEditor.ready(function(K) {
                    editor_${tpl.columnCode} = K.create('textarea[name="${tpl.columnCode}"]', {
                      items: ["source", "|", "undo", "redo", "|", "preview", "template", "code", "cut", "copy", "paste", "plainpaste", "wordpaste", "|", "justifyleft",
                        "justifycenter", "justifyright", "justifyfull", "insertorderedlist", "insertunorderedlist", "indent", "outdent", "subscript", "superscript",
                        "clearhtml", "quickformat", "selectall", "|", "fullscreen", "/", "formatblock", "fontname", "fontsize", "|", "forecolor", "hilitecolor",
                        "bold", "italic", "underline", "strikethrough", "lineheight", "removeformat", "|", "image", "multiimage", "insertfile", "table",
                        "hr", "emoticons", "baidumap", "pagebreak"],
                      allowFileManager : true,
                      allowImageUpload : true,
                      uploadJson  : '${basepath}/assets/kindedit/jsp/upload_kind.jsp'
                    });
                  });
                </script>
              </td>
            </tr>
          </c:when>
        </c:choose>
      </c:forEach>
    </table>
  </form>
</body>
<script>

  var finishSubmit = function(){
    layer.msg('提交功能未完待续', {time: 3000, icon:6});
  }

  //保存
  var formSubmit = function(){
    var formval = serializeForm(taskTableForm);
    formval = JSON.parse(formval);
    <c:forEach items="${dataList}" var="tpl">
      <c:choose>
        <c:when test="${tpl.type==3 and tpl.itemType==0}"><!--富文本类型-->
        formval.${tpl.columnCode} = editor_${tpl.columnCode}.html();
        </c:when>
      </c:choose>
    </c:forEach>
    //console.log(formval);
    var dataList = new Array();
    dataList.push(formval);   
    $.ajax({
      url: '${path}/tasktrans/saveFormData',
      contentType: "application/json",
      type:'POST',
      data:  JSON.stringify(dataList),
      dataType: 'json',
      success: function(doc) {
          layer.msg(doc.msg, {time: 3000, icon:6});
        //layer.msg(doc.msg, {time: 3000, icon:6});
      }
    });
  }
</script>
</html>
